home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12963 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: switching base 10 to hex
  5. Date: 3 Apr 1996 10:12 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <3APR199610123176@erich.triumf.ca>
  9. References: <4ju6a9$kl6@coranto.ucs.mun.ca>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4ju6a9$kl6@coranto.ucs.mun.ca>, jdeeley@calvin.stemnet.nf.ca (J.Deeley) writes...
  14.  
  15. >I am teaching myself to program in C using a book that came with my
  16. >compiler. In the book I just ran into a small section which deals with
  17. >switching base 10 numbers to base two numbers (no problems there, thats
  18. >easy) and also switching base 10 numbers to hexidecimal (base 16).
  19. >Agh! My book does a lousy job of explaining how that works, and one of
  20. >the alternative explanations I found on the net does no better. Can
  21. >someone give me a good, simple way to get a hexadecimal number from a
  22. >normal number? Like the number 400 for instance? Go slow...
  23.  
  24. Within your program, all integers are stored and manipulated as binary 
  25. numbers.  
  26.  
  27. If you want to print a number in decimal, you use:
  28.     printf("%d", num);
  29. To print in hex, use:
  30.     printf(%x", num);
  31. or, in octal:
  32.     printf("%o", num);
  33.  
  34. Look up the format  specifiers for printf()....
  35.  
  36.  
  37. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  38. Internet: bennett@triumf.ca         | of one another only when one can be
  39. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  40. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  41. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  42. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  43.  
  44.